package cj.hrm.dao;


import cj.hrm.dao.provider.ResumeDynaSqlProvider;
import cj.hrm.entity.Resume;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;
import java.util.Map;

import static cj.hrm.util.common.HrmConstants.*;

public interface ResumeDao {

	//动态插入简历
	@SelectProvider(type= ResumeDynaSqlProvider.class,method="insertResume")
	void insert_Resume(Resume resume);
	//根据参数查询简历总数
	@SelectProvider(type=ResumeDynaSqlProvider.class,method="count")
	int count(Map<String, Object> params);
	@Select("select count(*) from "+RESUMETABLE+" where jobtype like CONCAT('%',#{content},'%')"
			+ "or sex_id =(select id from "+SEXTABLE+" where name like CONCAT('%',#{content},'%'))"
			+ "or education_id =(select id from "+EDUCATIONTABLE+" where name like CONCAT('%',#{content},'%'))"
			+ "or status_id =(select id from "+STATUSTABLE+" where name like CONCAT('%',#{content},'%'))"
			+ "or createdate like binary CONCAT('%',#{content},'%')"
			+ "or content like CONCAT('%',#{content},'%')"
			+ "or name like CONCAT('%',#{content},'%')"
			+ "or email like CONCAT('%',#{content},'%')"
			+ "or phone like CONCAT('%',#{content},'%')")
	Integer countResume(String content);

	//根据参数动态查询简历
	@SelectProvider(type=ResumeDynaSqlProvider.class,method="selectWhitParam")
	@Results({
		@Result(id=true,column="id",property="id"),
		@Result(column="sex_id",property="sex",
		one=@One(select="cj.hrm.dao.SexDao.selectById",
		fetchType=FetchType.EAGER)),
		@Result(column="education_id",property="education",
		one=@One(select="cj.hrm.dao.EducationDao.selectById",
		fetchType=FetchType.EAGER)),
		@Result(column="status_id",property="status",
		one=@One(select="cj.hrm.dao.StatusDao.selectById",
	fetchType=FetchType.EAGER))
	})
	List<Resume> selectByPage(Map<String, Object> params);

	//根据id查询简历
	@Select("select * from "+RESUMETABLE+" where id = #{id}")
	@Results({
		@Result(id=true,column="id",property="id"),
		@Result(column="sex_id",property="sex",
		one=@One(select="cj.hrm.dao.SexDao.selectById",
		fetchType=FetchType.EAGER)),
		@Result(column="education_id",property="education",
		one=@One(select="cj.hrm.dao.EducationDao.selectById",
		fetchType=FetchType.EAGER)),
		@Result(column="status_id",property="status",
		one=@One(select="cj.hrm.dao.StatusDao.selectById",
	fetchType=FetchType.EAGER))
	})
	Resume selectById(Integer id);
	//动态修改简历
	@SelectProvider(type=ResumeDynaSqlProvider.class,method="updateResume")
	void update_Resume(Resume resume);
	// 根据id删除简历
	@Delete(" delete from "+RESUMETABLE+" where id = #{id} ")
	void deleteById(Integer id);


	@Select("select * from "+RESUMETABLE+" where jobtype like CONCAT('%',#{content},'%')"
			+ "or sex_id =(select id from "+SEXTABLE+" where name like CONCAT('%',#{content},'%'))"
			+ "or education_id =(select id from "+EDUCATIONTABLE+" where name like CONCAT('%',#{content},'%'))"
			+ "or status_id =(select id from "+STATUSTABLE+" where name like CONCAT('%',#{content},'%'))"
			+ "or createdate like binary CONCAT('%',#{content},'%')"
			+ "or content like CONCAT('%',#{content},'%')"
			+ "or name like CONCAT('%',#{content},'%')"
			+ "or email like CONCAT('%',#{content},'%')"
			+ "or phone like CONCAT('%',#{content},'%')")
	@Results({
		@Result(id=true,column="id",property="id"),
		@Result(column="sex_id",property="sex",
		one=@One(select="cj.hrm.dao.SexDao.selectById",
		fetchType=FetchType.EAGER)),
		@Result(column="education_id",property="education",
		one=@One(select="cj.hrm.dao.EducationDao.selectById",
		fetchType=FetchType.EAGER)),
		@Result(column="status_id",property="status",
		one=@One(select="cj.hrm.dao.StatusDao.selectById",
	fetchType=FetchType.EAGER))
	})
	List<Resume> get_LikeList(String content);

}
